<?php


namespace App\Sevrice;


use Illuminate\Support\Facades\Mail;

/**
 * Interface Subject
 * @package App\Sevrice
 *管理观察者接口类
 */
interface Subject
{
    function regsiter(Observer $Observer);

    function notify($info);
}

/**
 * Class Watch
 * @package App\Sevrice
 * 观察者入口类
 */
class Watch implements Subject
{
    public $array = [];

    public function regsiter(Observer $Observer)
    {
        $this->array[] = $Observer;
    }

    public function notify($info)
    {
        foreach ($this->array as $v) {
            $v->watch($info);
        }
    }
}

/**
 * Interface Observer
 * @package App\Sevrice
 * 观察者执行
 */
interface Observer
{
    function watch($info);
}
/**
 * Class one
 * @package App\Sevrice
 * 观察者1，用于提示上线通知
 */
class one implements Observer
{
    public function watch($info)
    {
        $email = ['1764749557@qq.com'];
        Mail::raw("您关注的$info"."博主上线了,快去围观吧", function ($query) use ($email) {
            $query->subject('抖音推荐')->to($email);
        });
    }
}

/**
 * Class two
 * @package App\Sevrice
 * 观察者2，用于提示下线通知
 */
class two implements Observer
{
    public function watch($info)
    {
        $email = ['1764749557@qq.com'];
        Mail::raw('您关注的'.$info.'博主下线了,快去睡觉吧', function ($query) use ($email) {
            $query->subject('抖音养生')->to($email);
        });
    }
}